package cn.zhj.blog.service.impl;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;

import cn.zhj.blog.domain.ArticleType;
import cn.zhj.blog.mapper.ArticleTypeMapper;
import cn.zhj.blog.query.ArticleTypeQuery;
import cn.zhj.blog.service.IArticleTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 业务实现类：文章类型ArticleType
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class ArticleTypeServiceImpl implements IArticleTypeService {
    @Autowired
    private ArticleTypeMapper articleTypeMapper;

    @Override
    public List<ArticleType> findAll() {
        return articleTypeMapper.findAll();
    }

    @Override
    public ArticleType findOne(Long id) {
        return articleTypeMapper.findOne(id);
    }

    @Transactional
    @Override
    public void add(ArticleType articleType) {
        articleTypeMapper.add(articleType);
    }

    @Transactional
    @Override
    public void update(ArticleType articleType) {
        articleTypeMapper.update(articleType);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        articleTypeMapper.delete(id);
    }

    @Transactional
    @Override
    public void patchDel(Long[] ids) {
        articleTypeMapper.patchDel(ids);
    }

    @Override
    public PageInfo<ArticleType> queryPage(ArticleTypeQuery articleTypeQuery) {
        //开启分页
        PageHelper.startPage(articleTypeQuery.getCurrentPage(),articleTypeQuery.getPageSize());
        //1.首先会查询总条数
        //2.会根据方言或驱动名进行分页查询数据 - mysql - limit
        //3.会自动计算limit的第一个参数

        List<ArticleType> list = articleTypeMapper.queryPage(articleTypeQuery);
        //调用PageInfo的有参会计算其他参数
        PageInfo<ArticleType> pageInfo = new PageInfo<ArticleType>(list);
        return pageInfo;
    }
}
